package com.itbaizhan.shopping_common.interceptor;

import com.itbaizhan.shopping_common.utils.JWTUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author spf
 * @date 2024/1/12
 * @time 15:44
 */
// 令牌拦截器，验证令牌
public class JWTInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 获取请求头中的令牌
        String token = request.getHeader("token");
        // 验证token
        JWTUtil.verify(token);
        return true;
    }
}
